package com.axend.aerosense.dev.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;

import com.axend.aerosense.base.fragment.MvvmBaseFragment;
import com.axend.aerosense.base.impl.ILoadDataResult;
import com.axend.aerosense.base.viewmodel.BaseViewModelFactroy;
import com.axend.aerosense.common.bean.RadarBean;
import com.axend.aerosense.dev.BR;
import com.axend.aerosense.dev.R;
import com.axend.aerosense.dev.databinding.DevFragmentWavveSettingBinding;
import com.axend.aerosense.dev.entity.DevRadarSettingBean;
import com.axend.aerosense.dev.entity.DevRadarSettingResBean;
import com.axend.aerosense.dev.viewmodel.DevWavveSettingViewModel;

public class DevWavveSettingFragment
        extends MvvmBaseFragment<DevFragmentWavveSettingBinding, DevWavveSettingViewModel>
        implements ILoadDataResult<DevRadarSettingResBean> {

    private RadarBean radarBean;

    public static DevWavveSettingFragment getInstance(){
        return new DevWavveSettingFragment();
    }

    @Override
    public int getLayoutId() {
        return R.layout.dev_fragment_wavve_setting;
    }

    @Override
    public int getBindingVariable() {
        return BR.data;
    }

    @Override
    protected DevWavveSettingViewModel getViewModel() {
        BaseViewModelFactroy<DevRadarSettingResBean> myViewModelFactory = new BaseViewModelFactroy<>(this, this);
        return new ViewModelProvider(this, myViewModelFactory).get(DevWavveSettingViewModel.class);
    }

    @Override
    protected void onRetryBtnClick() {
        showLoading();
        viewModel.onLoad();
    }

    @Override
    protected void initParameters() {
        super.initParameters();
        Bundle bundle = getArguments();
        if (null != bundle){
            radarBean = (RadarBean) bundle.getSerializable(DevDeviceSettingsFragment.ARG_PARAM);
        }
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        setLoadSir(viewDataBinding.devContentView);
        onRetryBtnClick();
    }

    private void initView(){
        viewModel.setRadarBean(radarBean);

        viewDataBinding.devBtnSave.setOnClickListener(v -> {
            viewModel.setSettings(getActivity());
        });
    }

    @Override
    public void loadDataSuccess(DevRadarSettingResBean bean) {

    }

    @Override
    public void loadDataFail(String decs) {

    }
}
